﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using RTGS.Library;
using RTGS.Library.Entities.Rtgs;
using RTGS.Library.Enum;
using RTGS.Library.Interfaces;

namespace RTGS.Library.DataAccess.Rtgs
{
    public partial class stpConfigRepo
    {
        //public bool Save(stpConfig domain)
        //{
        //    bool result = false;
        //    using (SqlConnection conn = new SqlConnection(connectionString))
        //    {
        //        using (SqlCommand cmd = conn.CreateCommand())
        //        {
        //            cmd.CommandText = "INSERT INTO stp_config(configname, configvalue) VALUES(@configname, @configvalue)";
        //            cmd.CommandType = CommandType.Text;
        //            cmd.Parameters.Add("@configname", SqlDbType.VarChar).Value = (object)domain.configname ?? DBNull.Value;
        //            cmd.Parameters.Add("@configvalue", SqlDbType.VarChar).Value = (object)domain.configvalue ?? DBNull.Value;
                    
        //            try
        //            {
        //                conn.Open();
        //                cmd.ExecuteNonQuery();
        //                result = true;
        //            }
        //            catch (Exception ex)
        //            {
        //                errorLog = ex.Message;
        //            }
        //            finally
        //            {
        //                if (conn.State == ConnectionState.Open) conn.Close();
        //            }

        //        }
        //    }
        //    return result;
        //}

        //public bool Update(stpConfig domain)
        //{
        //    int result = 0;
        //    using (SqlConnection conn = new SqlConnection(connectionString))
        //    {
        //        using (SqlCommand cmd = conn.CreateCommand())
        //        {
        //            cmd.CommandText = "UPDATE stp_config SET configvalue = @configvalue WHERE configname = @configname";
        //            cmd.CommandType = CommandType.Text;
        //            cmd.Parameters.Add("@configvalue", SqlDbType.VarChar).Value = domain.configvalue;
        //            cmd.Parameters.Add("@configname", SqlDbType.VarChar).Value = (object)domain.configvalue ?? DBNull.Value;
                    
        //            try
        //            {
        //                conn.Open();
        //                result = cmd.ExecuteNonQuery();
        //            }
        //            catch (Exception ex)
        //            {
        //                errorLog = ex.Message;
        //            }
        //            finally
        //            {
        //                if (conn.State == ConnectionState.Open) conn.Close();
        //            }
        //        }
        //    }
        //    return (result > 0);
        //}

        //public bool Delete(string key)
        //{
        //    bool result = false;
        //    using (SqlConnection conn = new SqlConnection(connectionString))
        //    {
        //        using (SqlCommand cmd = conn.CreateCommand())
        //        {
        //            cmd.CommandText = "DELETE FROM stp_config WHERE configname = @configname";
        //            cmd.CommandType = CommandType.Text;
        //            cmd.Parameters.Add("@configname", SqlDbType.VarChar).Value = key;

        //            try
        //            {
        //                conn.Open();
        //                cmd.ExecuteNonQuery();
        //                result = true;
        //            }
        //            catch (Exception ex)
        //            {
        //                errorLog = ex.Message;
        //            }
        //            finally
        //            {
        //                if (conn.State == ConnectionState.Open) conn.Close();
        //            }
        //        }
        //    }
        //    return result;
        //}

        //public stpConfig GetById(string key)
        //{
        //    stpConfig t = new stpConfig();
        //    using (SqlConnection conn = new SqlConnection(connectionString))
        //    {
        //        using (SqlCommand cmd = conn.CreateCommand())
        //        {
        //            cmd.CommandText = "SELECT configname, configvalue FROM stp_config WHERE configname = @configname";
        //            cmd.CommandType = CommandType.Text;
        //            cmd.Parameters.Add("@configname", SqlDbType.VarChar).Value = key;
        //            try
        //            {
        //                conn.Open();
        //                using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
        //                {
        //                    while (dr.Read())
        //                    {

        //                        t.configname = dr[stpConfig.Fields.configname] == DBNull.Value ? string.Empty : dr[stpConfig.Fields.configname].ToString();
        //                        t.configvalue = dr[stpConfig.Fields.configvalue] == DBNull.Value ? string.Empty : dr[stpConfig.Fields.configvalue].ToString();
                                
        //                    }
        //                }
        //            }
        //            catch (Exception ex)
        //            {
        //                errorLog = ex.Message;
        //            }
        //            finally
        //            {
        //                if (conn.State == ConnectionState.Open) conn.Close();
        //            }
        //        }
        //    }
        //    return t;
        //}
        

    }

    public partial class stpRecordDetailORepo
    {
//        public stpRecordDetailO GetById(string key)
//        {
//            stpRecordDetailO t = new stpRecordDetailO();
//            using (SqlConnection conn = new SqlConnection(connectionString))
//            {
//                using (SqlCommand cmd = conn.CreateCommand())
//                {
//                    cmd.CommandText = @"SELECT [RECORD_DETAIL_OTR_RecordType]
//                                      ,[RECORD_DETAIL_OTR_TransactionCode]
//                                      ,[RECORD_DETAIL_OTR_FromMember]
//                                      ,[RECORD_DETAIL_OTR_ToMember]
//                                      ,[RECORD_DETAIL_OTR_ReceivingBankBrCode]
//                                      ,[RECORD_DETAIL_OTR_TRN]
//                                      ,[RECORD_DETAIL_OTR_RelatedTRN]
//                                      ,[RECORD_DETAIL_OTR_Amount]
//                                      ,[RECORD_DETAIL_OTR_ValueDate]
//                                      ,[RECORD_DETAIL_OST_SendersReferenceNumber]
//                                      ,[RECORD_DETAIL_OST_ReceiversReferenceNumber]
//                                      ,[RECORD_DETAIL_OST_DealStockCode]
//                                      ,[RECORD_DETAIL_OST_ToAccountNumber]
//                                      ,[RECORD_DETAIL_OST_ToAccountName]
//                                      ,[RECORD_DETAIL_OST_FromAccountNumber]
//                                      ,[RECORD_DETAIL_OST_FromAccountName]
//                                      ,[RECORD_DETAIL_OST_PaymentDetails]
//                                      ,[RECORD_DETAIL_OST_MemberInfo]
//                                      ,[RECORD_DETAIL_OST_OriginatingNumber]
//                                      ,[RECORD_DETAIL_OST_OriginatingName]
//                                      ,[RECORD_DETAIL_OST_UltimateBenefAccount]
//                                      ,[RECORD_DETAIL_OST_UltimateBenefName]
//                                      ,[RECORD_DETAIL_OST_Currency]
//                                      ,[RECORD_DETAIL_OST_ExchangeRate]
//                                      ,[RECORD_DETAIL_OST_InterestRate]
//                                      ,[RECORD_DETAIL_OST_Period]
//                                      ,[RECORD_DETAIL_OST_SAKTINumber]
//                                      ,[RECORD_DETAIL_ORECORD_OH_BatchReference]
//                                      ,[RECORD_DETAIL_ORecordTime]
//                                      ,[RECORD_DETAIL_ORECORD_SWIFT_ODateTime]
//                                      ,[RECORD_DETAIL_Status]
//                                  FROM [STP_RECORD_DETAIL_O]
//                                 WHERE [RECORD_DETAIL_OTR_RelatedTRN]=@Id";
//                    cmd.CommandType = CommandType.Text;
//                    cmd.Parameters.Add("@Id", SqlDbType.VarChar).Value = key;
//                    try
//                    {
//                        conn.Open();
//                        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
//                        {
//                            while (dr.Read())
//                            {
                               
//                                t.recordDetailOtrRecordtype = dr[stpRecordDetailO.Fields.recordDetailOtrRecordtype] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrRecordtype].ToString();
//                                t.recordDetailOtrTransactioncode = dr[stpRecordDetailO.Fields.recordDetailOtrTransactioncode] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrTransactioncode].ToString();
//                                t.recordDetailOtrFrommember = dr[stpRecordDetailO.Fields.recordDetailOtrFrommember] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrFrommember].ToString();
//                                t.recordDetailOtrTomember = dr[stpRecordDetailO.Fields.recordDetailOtrTomember] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrTomember].ToString();
//                                t.recordDetailOtrReceivingbankbrcode = dr[stpRecordDetailO.Fields.recordDetailOtrReceivingbankbrcode] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrReceivingbankbrcode].ToString();
//                                t.recordDetailOtrTrn = dr[stpRecordDetailO.Fields.recordDetailOtrTrn] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrTrn].ToString();
//                                t.recordDetailOtrRelatedtrn = dr[stpRecordDetailO.Fields.recordDetailOtrRelatedtrn] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrRelatedtrn].ToString();
//                                t.recordDetailOtrAmount = dr[stpRecordDetailO.Fields.recordDetailOtrAmount] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrAmount].ToString();
//                                t.recordDetailOtrValuedate = dr[stpRecordDetailO.Fields.recordDetailOtrValuedate] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOtrValuedate].ToString();
//                                t.recordDetailOstSendersreferencenumber = dr[stpRecordDetailO.Fields.recordDetailOstSendersreferencenumber] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstSendersreferencenumber].ToString();
//                                t.recordDetailOstReceiversreferencenumber = dr[stpRecordDetailO.Fields.recordDetailOstReceiversreferencenumber] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstReceiversreferencenumber].ToString();
//                                t.recordDetailOstDealstockcode = dr[stpRecordDetailO.Fields.recordDetailOstDealstockcode] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstDealstockcode].ToString();
//                                t.recordDetailOstToaccountnumber = dr[stpRecordDetailO.Fields.recordDetailOstToaccountnumber] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstToaccountnumber].ToString();
//                                t.recordDetailOstToaccountname = dr[stpRecordDetailO.Fields.recordDetailOstToaccountname] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstToaccountname].ToString();
//                                t.recordDetailOstFromaccountnumber = dr[stpRecordDetailO.Fields.recordDetailOstFromaccountnumber] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstFromaccountnumber].ToString();
//                                t.recordDetailOstFromaccountname = dr[stpRecordDetailO.Fields.recordDetailOstFromaccountname] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstFromaccountname].ToString();
//                                t.recordDetailOstPaymentdetails = dr[stpRecordDetailO.Fields.recordDetailOstPaymentdetails] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstPaymentdetails].ToString();
//                                t.recordDetailOstMemberinfo = dr[stpRecordDetailO.Fields.recordDetailOstMemberinfo] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstMemberinfo].ToString();
//                                t.recordDetailOstOriginatingnumber = dr[stpRecordDetailO.Fields.recordDetailOstOriginatingnumber] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstOriginatingnumber].ToString();
//                                t.recordDetailOstOriginatingname = dr[stpRecordDetailO.Fields.recordDetailOstOriginatingname] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstOriginatingname].ToString();
//                                t.recordDetailOstUltimatebenefaccount = dr[stpRecordDetailO.Fields.recordDetailOstUltimatebenefaccount] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstUltimatebenefaccount].ToString();
//                                t.recordDetailOstUltimatebenefname = dr[stpRecordDetailO.Fields.recordDetailOstUltimatebenefname] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstUltimatebenefname].ToString();
//                                t.recordDetailOstCurrency = dr[stpRecordDetailO.Fields.recordDetailOstCurrency] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstCurrency].ToString();
//                                t.recordDetailOstExchangerate = dr[stpRecordDetailO.Fields.recordDetailOstExchangerate] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstExchangerate].ToString();
//                                t.recordDetailOstInterestrate = dr[stpRecordDetailO.Fields.recordDetailOstInterestrate] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstInterestrate].ToString();
//                                t.recordDetailOstPeriod = dr[stpRecordDetailO.Fields.recordDetailOstPeriod] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstPeriod].ToString();
//                                t.recordDetailOstSaktinumber = dr[stpRecordDetailO.Fields.recordDetailOstSaktinumber] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOstSaktinumber].ToString();
//                                t.recordDetailOrecordOhBatchreference = dr[stpRecordDetailO.Fields.recordDetailOrecordOhBatchreference] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailOrecordOhBatchreference].ToString();
//                                t.recordDetailOrecordtime = dr[stpRecordDetailO.Fields.recordDetailOrecordtime] == DBNull.Value ? DateTime.Now : DateTime.Parse(dr[stpRecordDetailO.Fields.recordDetailOrecordtime].ToString());
//                                t.recordDetailOrecordSwiftOdatetime = dr[stpRecordDetailO.Fields.recordDetailOrecordSwiftOdatetime] == DBNull.Value ? (DateTime?)null : DateTime.Parse(dr[stpRecordDetailO.Fields.recordDetailOrecordSwiftOdatetime].ToString());
//                                t.recordDetailStatus = dr[stpRecordDetailO.Fields.recordDetailStatus] == DBNull.Value ? string.Empty : dr[stpRecordDetailO.Fields.recordDetailStatus].ToString();
                               
                               
//                            }
//                        }
//                    }
//                    catch (Exception ex)
//                    {
//                        errorLog = ex.Message;
//                    }
//                    finally
//                    {
//                        if (conn.State == ConnectionState.Open) conn.Close();
//                    }
//                }
//            }
//            return t;
//        }

        public DataTable GeData()
        {
            DataTable dt = new DataTable();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT [RECORD_DETAIL_OTR_RecordType]
                                      ,[RECORD_DETAIL_OTR_TransactionCode]
                                      ,[RECORD_DETAIL_OTR_FromMember]
                                      ,[RECORD_DETAIL_OTR_ToMember]
                                      ,[RECORD_DETAIL_OTR_ReceivingBankBrCode]
                                      ,[RECORD_DETAIL_OTR_TRN]
                                      ,[RECORD_DETAIL_OTR_RelatedTRN]
                                      ,[RECORD_DETAIL_OTR_Amount]
                                      ,[RECORD_DETAIL_OTR_ValueDate]
                                      ,[RECORD_DETAIL_OST_SendersReferenceNumber]
                                      ,[RECORD_DETAIL_OST_ReceiversReferenceNumber]
                                      ,[RECORD_DETAIL_OST_DealStockCode]
                                      ,[RECORD_DETAIL_OST_ToAccountNumber]
                                      ,[RECORD_DETAIL_OST_ToAccountName]
                                      ,[RECORD_DETAIL_OST_FromAccountNumber]
                                      ,[RECORD_DETAIL_OST_FromAccountName]
                                      ,[RECORD_DETAIL_OST_PaymentDetails]
                                      ,[RECORD_DETAIL_OST_MemberInfo]
                                      ,[RECORD_DETAIL_OST_OriginatingNumber]
                                      ,[RECORD_DETAIL_OST_OriginatingName]
                                      ,[RECORD_DETAIL_OST_UltimateBenefAccount]
                                      ,[RECORD_DETAIL_OST_UltimateBenefName]
                                      ,[RECORD_DETAIL_OST_Currency]
                                      ,[RECORD_DETAIL_OST_ExchangeRate]
                                      ,[RECORD_DETAIL_OST_InterestRate]
                                      ,[RECORD_DETAIL_OST_Period]
                                      ,[RECORD_DETAIL_OST_SAKTINumber]
                                      ,[RECORD_DETAIL_ORECORD_OH_BatchReference]
                                      ,[RECORD_DETAIL_ORecordTime]
                                      ,[RECORD_DETAIL_ORECORD_SWIFT_ODateTime]
                                      ,[RECORD_DETAIL_Status]
                                  FROM [STP_RECORD_DETAIL_O]";

                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    try
                    {
                        conn.Open();
                        da.Fill(dt);
                    }
                    catch (Exception ex)
                    {
                        errorLog = ex.Message;
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }

                }
            }

            return dt;

        }


        //public bool UpdateByStatus(stpRecordDetailO domain,string status,string reasoncode)
        //{
        //    int result = 0;
        //    using (SqlConnection conn = new SqlConnection(connectionString))
        //    {
        //        using (SqlCommand cmd = conn.CreateCommand())
        //        {
        //            StringBuilder sql = new StringBuilder();

        //            sql.AppendLine("UPDATE STP_RECORD_DETAIL_O SET RECORD_DETAIL_ORECORD_Status = @recordDetailOrecordStatus");
        //            if (status.Trim() == "repair")
        //            {
        //                if (reasoncode == "001")
        //                {
        //                    sql.AppendLine(",RECORD_DETAIL_OTR_ValueDate = @recordDetailOtrValuedate");

        //                    cmd.Parameters.Add("@recordDetailOtrValuedate", SqlDbType.VarChar).Value = (object)domain.recordDetailOtrValuedate ?? DBNull.Value;
        //                }

        //                if (reasoncode == "002")
        //                {


        //                    sql.AppendLine(",RECORD_DETAIL_OST_ToAccountName = @recordDetailOstToaccountname");
        //                    sql.AppendLine(",RECORD_DETAIL_OST_ToAccountNumber = @recordDetailOstToaccountnumber");
        //                    sql.AppendLine(",RECORD_DETAIL_OTR_ToMember = @recordDetailOtrTomember");
        //                    sql.AppendLine(",RECORD_DETAIL_OST_FromAccountName = @recordDetailOstFromaccountname");
        //                    sql.AppendLine(",RECORD_DETAIL_OST_FromAccountNumber = @recordDetailOstFromaccountnumber");
        //                    sql.AppendLine(",RECORD_DETAIL_OTR_FromMember = @recordDetailOtrFrommember");

        //                    cmd.Parameters.Add("@recordDetailOtrFrommember", SqlDbType.VarChar).Value = (object)domain.recordDetailOtrFrommember ?? DBNull.Value;
        //                    cmd.Parameters.Add("@recordDetailOtrTomember", SqlDbType.VarChar).Value = (object)domain.recordDetailOtrTomember ?? DBNull.Value;

        //                    cmd.Parameters.Add("@recordDetailOstToaccountnumber", SqlDbType.VarChar).Value = (object)domain.recordDetailOstToaccountnumber ?? DBNull.Value;
        //                    cmd.Parameters.Add("@recordDetailOstToaccountname", SqlDbType.VarChar).Value = (object)domain.recordDetailOstToaccountname ?? DBNull.Value;
        //                    cmd.Parameters.Add("@recordDetailOstFromaccountnumber", SqlDbType.VarChar).Value = (object)domain.recordDetailOstFromaccountnumber ?? DBNull.Value;
        //                    cmd.Parameters.Add("@recordDetailOstFromaccountname", SqlDbType.VarChar).Value = (object)domain.recordDetailOstFromaccountname ?? DBNull.Value;
        //                }

        //                if (reasoncode == "004")
        //                {
        //                    sql.AppendLine(",RECORD_DETAIL_OTR_Amount = @recordDetailOtrAmount");

        //                    cmd.Parameters.Add("@recordDetailOtrAmount", SqlDbType.VarChar).Value = (object)domain.recordDetailOtrAmount ?? DBNull.Value;
        //                }
        //            }

        //            sql.AppendLine(" WHERE RECORD_DETAIL_OTR_RelatedTRN = @recordDetailOtrRelatedtrn");

        //            cmd.CommandText = sql.ToString();

        //            cmd.Parameters.Add("@recordDetailOrecordStatus", SqlDbType.Char).Value = (object)domain.recordDetailOrecordStatus ?? DBNull.Value;
        //            cmd.Parameters.Add("@recordDetailOtrRelatedtrn", SqlDbType.VarChar).Value = domain.recordDetailOtrRelatedtrn;


        //            try
        //            {
        //                conn.Open();
        //                result = cmd.ExecuteNonQuery();
        //            }
        //            catch (Exception ex)
        //            {
        //                errorLog = ex.Message;
        //            }
        //            finally
        //            {
        //                if (conn.State == ConnectionState.Open) conn.Close();
        //            }
        //        }
        //    }
        //    return (result > 0);
        //}

    }

   

    public partial class stpUserRepo
    {
        public bool Insert(stpUser domain)
        {
            bool result = false;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO STP_USER(USERNAME, USERHASH, USERCREATE_TIME, USERGROUPID, USERMAX_AMOUNT) VALUES(@username, @userhash, @usercreateTime, @usergroupid, @usermaxAmount)";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = domain.username;
                    cmd.Parameters.Add("@userhash", SqlDbType.VarChar).Value = domain.userhash;
                    //cmd.Parameters.Add("@userxxxx", SqlDbType.VarChar).Value = domain.userxxxx;
                    cmd.Parameters.Add("@usercreateTime", SqlDbType.DateTime).Value = domain.usercreateTime;
                    //cmd.Parameters.Add("@userupdateTime", SqlDbType.DateTime).Value = domain.userupdateTime;
                    cmd.Parameters.Add("@usergroupid", SqlDbType.SmallInt).Value = domain.usergroupid;
                    cmd.Parameters.Add("@usermaxAmount", SqlDbType.Decimal).Value = domain.usermaxAmount;

                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        errorLog = ex.Message;
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }

                }
            }
            return result;
        }


        public bool Edit(stpUser domain)
        {
            int result = 0;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "UPDATE STP_USER SET USERNAME = @username,USERUPDATE_TIME = @userupdateTime, USERGROUPID = @usergroupid, USERMAX_AMOUNT = @usermaxAmount WHERE USERNAME = @username";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = domain.username;
                    //cmd.Parameters.Add("@userhash", SqlDbType.VarChar).Value = domain.userhash;
                    //cmd.Parameters.Add("@userxxxx", SqlDbType.VarChar).Value = domain.userxxxx;
                    cmd.Parameters.Add("@userupdateTime", SqlDbType.DateTime).Value = domain.userupdateTime;
                    cmd.Parameters.Add("@usergroupid", SqlDbType.SmallInt).Value = domain.usergroupid;
                    cmd.Parameters.Add("@usermaxAmount", SqlDbType.Decimal).Value = domain.usermaxAmount;

                    try
                    {
                        conn.Open();
                        result = cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        errorLog = ex.Message;
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }
                }
            }
            return (result > 0);
        }
    }

}
